//
//  SwipeGestureLayer.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/7/13.
//
//

#include "SwipeGestureLayer.h"
#include "MyUtilities.h"

bool SwipeGestureLayer::init(){

    return true;
}

void SwipeGestureLayer::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    CCPoint touchPosition = MyUtilities::getCoCosPointFromTouches(touches);
    touchBeginPoint = touchPosition;
}

void SwipeGestureLayer::ccTouchesMoved(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    //CCPoint touchPosition = MyUtilities::getCoCosPointFromTouches(touches);
}

void SwipeGestureLayer::ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){

    CCPoint touchPosition = MyUtilities::getCoCosPointFromTouches(touches);
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    double distanceThreshold = winSize.width * 0.1f;
    double distanceX = touchBeginPoint.x - touchPosition.x;

    if(MyUtilities::triTuyetDoi(distanceX) >= distanceThreshold){

        if(distanceX > 0){
            //to next
            goToNext();
        }else{
            //to prev
            goToPrev();
        }
    }
    
}

void SwipeGestureLayer::goToNext(){
    CCLOG("toNext");
}

void SwipeGestureLayer::goToPrev(){
    CCLOG("toPrev");
}